<?php

namespace app\dao\coupon;

use app\dao\BaseDao;
use app\model\marketing\coupon\Coupon;

/**
 * Class Coupon
 * @package app\dao\coupon
 */
class CouponDao extends BaseDao
{
    /**
     * Description: 设置模型
     * @return string
     */
    protected function setModel(): string
    {
        return Coupon::class;
    }

    /**
     * Description: 获取数据列表
     *
     * @param array $where
     * @param int   $page
     * @param int   $limit
     * @param array $with
     * @param array $attr
     *
     * @return array
     * @throws \ReflectionException
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function getList(array $where, int $page, int $limit, array $with = [], array $attr = [])
    {
        return $this->search($where)->page($page, $limit)->with($with)->withAttr($attr)->order('id desc')->select()->toArray();
    }

    //================接口====================
    public function getApiList(array $where, int $page, int $limit, string $field, array $with = [], array $attr = [])
    {
        return $this->search($where)
            ->when($page && $limit, function ($query) use ($page, $limit) {
                $query->page($page, $limit);
            })->field($field)->with($with)->withAttr($attr)->order('id asc')->select();
    }
}

